home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
prolog
/
pdprolog
/
robot.pro
< prev
next >
Wrap
Text File
|
1986-05-05
|
3KB
|
76 lines
/* John M. Linebarger
25 October 1985
Thi≤ prograφ act≤ a≤ ß robo⌠ tha⌠ will¼ wheε giveε ß to≡
ááááááleve∞ predicatσ oµ 'place(X,Y).'¼ placσ blocδ ß oε to≡ oµ
ááááááblocδ Γ iε thσ block≤ world« Thσ strateg∙ i≤ a≤ follows:
1« Takσ everythinτ ofµ oµ thσ receivinτ blocδ anΣ
áááááá áplacσ i⌠ oε thσ table.
áááááá
áááá 2« Takσ everythinτ ofµ oµ thσ sendinτ blocδ anΣ placσ
áááááá áái⌠ oε thσ table.
3« Place sendinτ blocδ ont∩ receivinτ block.
┴ majo≥ assumptioε here¼ oµ course¼ i≤ tha⌠ therσ i≤
ááááááunlimiteΣ room oε thσ table.
┴ featurσ oµ thi≤ prograφ i≤ thσ front-enΣ editinτ oµ
ááááááthσ top-level placσ predicate.
*/
on( [], a ).
on( a, b ).
on( b, c ).
on( c, d ).
on( d, table ).
on( [], e ).
on( e, f ).
on( f, g ).
on( g, table ).
place( table, _ ) :- print( 'Table cannot be moved.' ), nl.
place( A, A ) :- print( 'Cannot place block on top of itself.' ), nl.
place(A,_) :- (not(on(A,_)); not(on(_,A))), print( 'Block ' ),
ááááá print(A), print( ' does not exist.' ), nl.
place(A,B) :- on(A,B), print(A), print( ' is already on ' ),
print(B), print( '.' ), nl.
place(A,table) :- on(A,B), clear_top(B).
place(_,B) :- (not(on(B,_)); not(on(_,B))), print( 'Block ' ),
ááááá print(B), print( ' does not exist.' ), nl.
place( A, B ) :- clear_top( B ), clear_top( A ), on( A, C ),
ááááá below( A, C ),
retract( on( [], B ) ), asserta( on( A, B ) ),
print( 'Put ' ), print( A ), print( ' on ' ),
áááááá print( B ), print( '.' ), nl.
clear_top( X ) :- on( Y, X ), (on( [], X ); (remove( Y, X ),
áááááá clear_top( X ) ) ).
remove( [], X ) :- on( X, Y ), move( X, Y ).
remove( Y, X ) :- on( Z, Y ), remove( Z, Y ).
èbelow( A, table ) :- retract( on( A, table ) ).
below( A, C ) :- retract( on( A, C ) ), asserta( on ( [], C ) ).
move( X, table ).
move( X, Y ) :- retract( on( X, Y ) ), asserta( on( X, table ) ),
asserta( on( [], Y ) ), print( 'Put ' ),
áááááá print( X ), print( ' on table.' ), nl.
show :- on (X, Y ), print ( X ), print ( ' is currently on ' ),
print ( Y ), print ( '.' ), nl, fail.
show.
help :- print( 'This program acts like a robot in the blocks world' ),nl,
print( 'that will place one block on top of another with a' ),nl,
write( 'place(X,Y)' ), print( ' predicate. To see the current '),
nl, print( 'block configuration, type '), print( '\'show\'' ),
print( '.' ),nl, nl,
print('Written by John M. Linebarger as part of a course in'),nl,
print( 'Artificial Intelligence in the MBA program of New York'),
nl, print( 'University. The author\'s address is:'),
nl, print( '360 Davidson Street, Apt. 6, Bridgeport, CT 06605.'),
nl, print( 'Home phone is 203/333-5779.' ).